﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Drawing;
using System.Drawing.Imaging;
namespace System.Drawing
{
    public static class FileExtensions
    {

        public static byte[] ConvertImageToByteArray(this Stream file)
        {
            return Image.FromStream(file).ConvertImageToByteArray();
        }
        public static byte[] ConvertImageToByteArray(this Image ImageFile)
        {
            using (MemoryStream ms = new MemoryStream())
            {
                ImageFile.Save(ms, ImageFile.RawFormat);
                return ms.ToArray();
            }
        }
        public static byte[] ConvertImageToByteArray(this Bitmap bitMap)
        {
            using (var memory = new MemoryStream())
            {
                bitMap.Save(memory, bitMap.RawFormat);
                return memory.ToArray();
            }
        }
        public static byte[] ConvertImageToByteArray(this string fileName)
        {
            return new Bitmap(fileName).ConvertImageToByteArray();
        }

      
    }
}
